<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>

<%@ page import="java.util.*"%>
<%@ page import="forum.*"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript">
	var int = self.setInterval("checkNotifications()", 10000);

	function checkNotifications() {
		check();
	}
	
	function check(){
		var xmlhttp;
		if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp = new XMLHttpRequest();
		} else {// code for IE6, IE5
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.open("GET", "viewForumsProcessor?do=check", true);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					var friend = xmlhttp.responseXML.getElementsByTagName("response")[0].getElementsByTagName("friend")[0].firstChild.data;
					if (friend == "y")
						alert("Your friend added post");
					var author = xmlhttp.responseXML.getElementsByTagName("response")[0].getElementsByTagName("author")[0].firstChild.data;
					if (author == "y")
						alert("Post added to your thread");
				} else
					alert("Error\n" + xmlhttp.status + ":" + xmlhttp.statusText);
			}
		};
		xmlhttp.send(null);
	}
	
</script>
<title>Forums</title>
</head>
<body background="background.jpg" bgcolor="AliceBlue" link="Navy" text="Navy" >
<font face="COMIC SANS MS" >

	<h1 align="center">
		<font size="10"  color="FloralWhite">Forums</font>
	</h1>
	<table border="1" align="center" width=30% height=150 >
		<tbody>
			<%
				List<Forum> forumsList = (ArrayList) request.getAttribute("forums");
				Boolean isModerator = (Boolean) request.getSession().getAttribute(
						"isModerator");

				for (Forum f : forumsList) {
					out.println("<tr>");
					out.println("<td align=\"center\"><font size=\"5\" >" + f.getSubject() + "</font></td>");

					out.println("<td align=\"center\"><font size=\"5\" ><a href=\"viewForumsProcessor?do=show&id=" + f.getID()
							+ "\">Show</a></font></td>");
					if ((isModerator != null) && (isModerator.booleanValue()))
						out.println("<td><font size=\"5\" ><a href=\"viewForumsProcessor?do=delete&id="
								+ f.getID() + "\">Delete</a></font></td>");
					out.println("</tr>");
				}
			%>
		</tbody>
	</table>
	<br>
	<p align="center">
		<%
		if ((isModerator != null) && (isModerator.booleanValue())) {
			out.println("<font size=\"5\" ><a href=\"viewForumsProcessor?do=add\">Add a new forum</font></a>");
			out.println("<br><font size=\"5\" ><a href=\"removeUser\">Remove user</font></a>");
		}
	%>
		<br> 
			<font color="Navy" size ="5">
			<a href="viewFriends" size=5>Show friends</a> <br> <a
			href="logout">logout</a>
			</font>
	</p>
</font>
</body>
</html>